package com.eedi.framework.tenant.dal.mapper;

import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import com.eedi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.eedi.framework.tenant.controller.sys.vo.tenant.TenantPageReq;
import com.eedi.framework.tenant.controller.sys.vo.tenant.TenantResp;
import com.eedi.framework.tenant.dal.dataobject.TenantDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

/**
 * 租户 Mapper
 *
 * @author 永聚长青源码
 */
@Mapper
public interface TenantMapper extends BaseMapperX<TenantDO> {

    default PageResult<TenantDO> selectPage(TenantPageReq reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TenantDO>()
                .likeIfPresent(TenantDO::getSysTenantName, reqVO.getSysTenantName())
                .likeIfPresent(TenantDO::getSysTenantContactName, reqVO.getSysTenantContactName())
                .likeIfPresent(TenantDO::getSysTenantContactMobile, reqVO.getSysTenantContactMobile())
                .eqIfPresent(TenantDO::getSysTenantStatus, reqVO.getSysTenantStatus())
                .betweenIfPresent(TenantDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TenantDO::getId));
    }

    default TenantDO selectByName(String name) {
        return selectOne(TenantDO::getSysTenantName, name);
    }

    default TenantDO selectBySysWebsite(String sysTenantWebsite) {
        return selectOne(TenantDO::getSysTenantWebsite, sysTenantWebsite);
    }

    default List<TenantResp> getByTenantIds(Collection<String> sysTenantIds) {
        List<TenantDO> tenants = selectList(new LambdaQueryWrapperX<TenantDO>()
                .inIfPresent(TenantDO::getSysTenantId, sysTenantIds));
        return BeanUtils.toBean(tenants, TenantResp.class);
    }


}
